﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using XMLSpreadGear.Core;

namespace XMLSpreadGear.Templates
{
    public class Data:BaseElement
    {
        private DataType dtDataType;

        public DataType DataType
        {
            get { return dtDataType; }
            set { dtDataType = value; }
        }
        private bool? bTick;

        public bool? Tick
        {
            get { return bTick; }
            set { bTick = value; }
        }

        private string strValue;

        public string Value
        {
            get { return strValue; }
            set { strValue = value; }
        }

        public Data(string strLocalName,DataType dataType)
            : base(strLocalName)
        {
            this.dtDataType = dataType;
        }
        public Data(string strLocalName, DataType dataType, bool tick)
            : this(strLocalName,dataType)
        {
            this.bTick = tick;
        }
        internal protected override IDictionary<string, string> RegisterElements()
        {
            IDictionary<string, string> dic = new Dictionary<string, string>();
            if(!string.IsNullOrEmpty(Value))
                dic.Add("Value", this.Value);
            return dic;
        }

        internal protected override IDictionary<string, string> RegisterAttributes()
        {
            IDictionary<string, string> dic = new Dictionary<string, string>();
            if(this.DataType != null)
                dic.Add("Type", Enum.GetName(typeof(DataType), this.DataType));

            if(this.Tick != null)
                dic.Add("Ticked", this.Tick.ToByte().ToString());

            return dic;
        }

        protected override void SetDefaults()
        {
            return;
        }

        internal override string GetAttributeNamespace()
        {
            return Contstants.SpredsheetAttributePrefix;
        }

        internal override string GetAttributeNamespaceURI()
        {
            return Contstants.SpredsheetAttributeNamespace;
        }
    }
}
